<?php
$parent = isset($CONFIG['parent']) ? (int)$CONFIG['parent'] : '';
$menu = Eleanor::$Cache->Get('menu_line'. Language::$main . $parent);

if($menu === false) {
	$p = $menu = '';
	if($parent) {
		$R = Eleanor::$Db->Query('SELECT `parents` FROM `'.P.'menu` WHERE `id`='.$parent.' LIMIT 1');
		if(!list($p) = $R->fetch_row())
			return'';
		$p .= $parent .',';
	}
	$R = Eleanor::$Db->Query('SELECT `title`,`url`,`eval_url`,`params` FROM `'.P.'menu` INNER JOIN `'.P.'menu_l` USING(`id`) WHERE `language` IN("","'.Language::$main.'") AND `status`=1 AND `parents`="'.$p.'" ORDER BY `parents` ASC, `pos` ASC LIMIT 3');
	$i = 0;
	while($a = $R->fetch_assoc()) {
		if($a['eval_url']) {
			ob_start();
			$f = create_function('$Eleanor', $a['eval_url']);
			if($f === false) {
				ob_end_clean();
				continue;
			}
			ob_end_clean();
			$url = $f($GLOBALS['Eleanor']);
		} else {
			$url = $a['url'];
		}
		if ($i === 0) {
			$menu .= '<li id="submenu_left_cell">
				<a href="'. $url .'" title="'. $a['title'] .'">
					<div id="submenu_left"></div>
					<img src="/templates/AutoDiagnostika/images/first_tool.png" width="72" height="73" alt="'. htmlspecialchars($a['title'], ENT_QUOTES) .'" title="'. htmlspecialchars($a['title'], ENT_QUOTES) .'">
					'. $a['title'] .'
					<div class="submenu_border_right"></div>
				</a>
			</li>';
		} elseif ($i === 1) {
			$menu .= '<li>
				<a href="'. $url .'" title="'. $a['title'] .'">
					<div id="submenu_border_left"></div>
					<img src="/templates/AutoDiagnostika/images/second_tool.png" width="72" height="73" alt="'. htmlspecialchars($a['title'], ENT_QUOTES) .'" title="'. htmlspecialchars($a['title'], ENT_QUOTES) .'">
					'. $a['title'] .'
					<div class="submenu_border_right"></div>
				</a>
			</li>';
		} elseif ($i === 2) {
			$menu .= '<li id="submenu_right_cell">
				<a href="'. $url .'" title="'. $a['title'] .'">
					<div id="submenu_right"></div>
					<img src="/templates/AutoDiagnostika/images/third_tool.png" width="72" height="73" alt="'. htmlspecialchars($a['title'], ENT_QUOTES) .'" title="'. htmlspecialchars($a['title'], ENT_QUOTES) .'">
					'. $a['title'] .'
				</a>
			</li>';
		}
		$i++;
	}
	$menu = '<aside id="submenu_container"><ul id="submenu">'. $menu .'</ul></aside>';
	Eleanor::$Cache->Put('menu_line'. Language::$main . $parent, $menu);
}
return $menu;
